﻿using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Personal.Servsers
{
    public class AddressGroupServers
    {
        private readonly IRepository<address_group> addressgroupRepository;

        public AddressGroupServers()
        {
            addressgroupRepository = new DapperRepository<address_group>();

        }
        
        internal void Add(address_group model)
        {
            addressgroupRepository.Insert(model);
        }

        internal void Update(address_group model)
        {
            addressgroupRepository.Update(model);
        }

        internal void Del(string id)
        {
            addressgroupRepository.DeleteByIds(id);
        }

        internal address_group GetModelById(string id)
        {
            address_group group = new address_group();
            if(id != "sg" && id != "default")
            {
                group = addressgroupRepository.GetById(id);
            }
            return group;
        }

        internal IList<address_group> GetGroupModel()
        {
            IList<address_group> groupLists = new List<address_group>();
            groupLists = addressgroupRepository.SqlWithParams("select * from address_group order by GROUP_ID desc ").ToList();
            return groupLists;
        }
        internal bool UpdateGroupNameById(int groupId, string groupName)
        {
            return addressgroupRepository.InsertUpdateOrDeleteSqlBool("update address_group set GROUP_NAME = '" + (string.IsNullOrEmpty(groupName) ? "" : groupName) + "' where GROUP_ID = " + groupId);
        }
    }
}